﻿<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>就诊卡列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/lobsteruiframe/weui/css/weui.css" />
    <link rel="stylesheet" href="/lobsteruiframe/weui/css/weuix.css" />
    <link href="/customer/css/blue.css" rel="stylesheet" />
    <script src="/lobsteruiframe/weui/js/zepto.min.js"></script>
    <script src="/lobsteruiframe/weui/js/zepto.weui.js"></script>
    <script src="/lobsteruiframe/weui/js/php.js"></script>
    <script src="/jslib/template-web.js"></script>
    <script src="/jslib/lobster.js"></script>
    <style type="text/css">
        .bodyCard {
            /**background-color: #fff;*/
            background-color: #07c160;
            margin: 15px 10px;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 1px 1px 5px #e1e1e1;
            opacity: 1;
            position: relative;
        }

        .bodyCard1 {
            /**background-color: #fff;*/
            background-color: #DFDFDF;
            margin: 15px 10px;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 1px 1px 5px #e1e1e1;
            opacity: 1;
            position: relative;
        }

        .titleimg {
            width: 50px;
            display: flex;
            align-items: center;
        }

        .titleimg image {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            box-sizing: border-box;
            border: 0.5px #e1e1e1 solid;
            background-color: #fff;
            padding-top: 5px;
        }

        .cardNo {
            /* padding-left: 30rpx; */
            padding-bottom: 10px;
            color: white;
            font-size: 17px;
            /* font-weight: bold; */
        }

        .titlelf {
            flex: 1;
            padding-left: 10px;
        }

        .titlename {
            font-size: 17px;
            display: flex;
            align-items: center;
        }

        .titlename1 {
            font-size: 17px;
            display: flex;
            align-items: center;
            color: #B0B0B0;
        }

        .image2 {
            padding-left: 10px;
            width: 45px;
            height: 20px;
        }

        .default {
            color: purple;
            background-color: rgb(73, 216, 73);
            font-size: 17px;
            margin-left: 10px;
            border-radius: 5px;
            padding: 0 5px;
        }

        .titletag {
            font-size: 17px;
            color: #fff;
            /**color:rgb(196, 193, 188);*/
            display: flex;
            padding-left: 15px;
        }

        .titletag1 {
            font-size: 17px;
            color: #B0B0B0;
            /**color:rgb(196, 193, 188);*/
            display: flex;
            padding-left: 15px;
        }

        .bodyCard .titleCard {
            display: flex;
            flex-direction: row;
            padding: 10px 15px;
            color: white;
            color: #fff;
            margin-right: 2.5px;
            border-radius: 2.5px;
        }

        .bodyCard1 .titleCard {
            display: flex;
            padding: 10px 15px;
            color: white;
            color: #B0B0B0;
            margin-right: 2.5px;
            border-radius: 2.5px;
        }

        .titlert {
            font-size: 17px;
            text-decoration: underline;
            padding-left: 10px;
            float: right;
        }

        .titlert1 {
            color: #07c160;
        }

        .bk {
            right: 10px;
            text-align: right;
            position: absolute;
        }

        .cardNo {
            font-size: 17px;
            min-height: 25px;
        }

        .contentleft {
            display: flex;
            flex-direction: column;
        }

        .fw {
            display: flex;
        }

        .contentright {
            flex: 1;
            text-align: right;
            margin-right: -42.5px;
        }

        .image3 {
            width: 117.5px;
            height: 108px;
            position: absolute;
            opacity: 0.2;
            top: 30px;
            right: -22.5px;
        }
    </style>
    <script>

        lobsterh5.main({
            data: {
                PatientId:0
            },
            //初始化页面
            pageload: function () {
                this.data.PatientId = lobsterh5.GetUrlParam("patientId");
                this.initdata();
            },
            //初始化事件
            initevent: function () {
                var self = this;
                //修改
                $(document).on("click", "#modify,#bindcard", function (obj) {
                    var info = JSON.parse(obj.currentTarget.dataset.info);
                    /* localStorage.setItem("patient", info);*/
                    var p_PatientId = "PatientId=" + self.data.PatientId;
                    var p_Code = "Code=" + info.Code;
                    var p_CardId = "CardId=" + (info.CardId || 0);
                    var p_CardNo = "CardNo=" + (info.CardNo || "");
                    var p_CardName = "CardName=" + encodeURI(encodeURI(info.Name || ""));
                    var p_BusinessText = "BusinessText=" + encodeURI(encodeURI(info.BusinessText || ""));
                    location.href = "bindcard.html?" + p_PatientId + "&" + p_Code + "&" + p_CardId + "&" + p_CardNo + "&" + p_CardName + "&" + p_BusinessText;
                })
            },
            initdata: function () {
                var self = this;
                self.getdata(self.data.PatientId);
            },
            getdata: function (patientId) {
                var self = this;
                lobsterh5.GET("/admin/v1/CPatient/GetCardTypeListByPId", { patientId: patientId }).then(res => {
                    if (res) {
                        var cardTypeList = res.cardTypeList;
                        var cardList = res.cardList;

                        self.showdata(cardTypeList, cardList, patientId);
                        self.initevent();
                    } else {
                        // $.toast(res.msg, "forbidden");
                    }
                }).catch(res => {
                    console.log(res);
                });
            },
            showdata: function (cardTyeList, cardList, patientId) {
                var self = this;
                var list = [];
                cardTyeList.forEach(function (item, index, items) {
                    if (item.BusinessText) {
                        item.items = item.BusinessText.replace(/,/g, ' / ');
                    } else {
                        item.items = '';
                    }
                    item.showCardNo = item.CardNo;
                    var codeModel = cardList.filter((x, index, arr) => {
                        return x.Code == item.Code
                    });
                    if (codeModel && codeModel.length > 0) {
                        item.CardNo = codeModel[0].CardNo;
                        if (item.Code == '2') {
                            item.showCardNo = self.hiddenStr(codeModel[0].CardNo, 4, 4);
                        } else {
                            item.showCardNo = self.hiddenStr(codeModel[0].CardNo, 0, 4);
                        }
                        item.CardId = codeModel[0].CardId;
                        item.IsDefault = codeModel[0].IsDefault;
                    }
                    item.PatientId = patientId;
                    list.push(item);
                });

                self.inittemp("tplcard", "maincontent", { list: list });
            },
            inittemp: function (tempid, _id, data) {
                var html = template(tempid, data);
                $("#" + _id).html(html);
            },
            hiddenStr(str, frontLen, endLen) {
                var len = str.length - frontLen - endLen;
                var xing = '';
                for (var i = 0; i < len; i++) {
                    xing += '*';
                }
                return str.substring(0, frontLen) + xing + str.substring(str.length - endLen);
            }
        })

    </script>
    <script type="text/template" id="tplcard">
        {{each list }}
        <div class="{{$value.CardId?'bodyCard':'bodyCard1'}}">
            <div class='titleCard'>
                <div class="{{$value.CardId?'titlename':'titlename1'}}">{{$value.Name}}</div>
                {{if($value.IsDefault==1)}}
                <image class="image2" src="../images/icon.png"></image>
                {{/if}}
                <div class="bk">
                    {{if(!$value.CardNo)}}
                    <div>
                        <div class="titlert titlert1" id="bindcard" data-info="{{$value}}">绑卡</div>
                        {{if($value.IsOnlineCreate==1 && OnlineCreateCard==1)}}
                        <div class="titlert titlert1" catchtap="onlineCreate">建档</div>
                        {{/if}}
                    </div>
                    {{/if}}
                    {{if($value.CardNo)}}
                    <div class="titlert " id="modify" data-info="{{$value}}">修改</div>
                    {{/if}}
                </div>
            </div>
            <div>
                <div class="{{$value.CardId?'titletag':'titletag1'}}">
                    <div class="contentleft">
                        <div class="fw">
                            <view>适用范围：</view>
                            <view class="taglist">{{$value.items}}</view>
                        </div>
                        <div class="cardNo">{{$value.showCardNo}}</div>
                    </div>
                </div>
            </div>
            <image class="image3" src="../images/card01.png"></image>
        </div>
        {{/each}}
    </script>

</head>

<body ontouchstart>
    <div class="maincontent" id="maincontent">

    </div>

</body>
</html>